<template>
  <div>
    <el-form ref="dataForm" :model="form" class="el-dialog__body" label-width="100px">
      <div class="ledgerTitle">项目信息</div>
      <el-row>
        <el-col :span="8">
          <el-form-item label-width="100px" label="项目名称">
            {{ form.projectName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="100px" label="编制人:">
            {{form.projectManage}}
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle">基本信息</div>
      <el-row>
        <el-col :span="8">
          <el-form-item label-width="100px" label="合同金额" prop="contractAmount">
            {{ form.contractAmount }} 元
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="100px" label="送审金额" prop="submittalAmount">
            {{ form.submittalAmount }} 元
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="100px" label="竣工验收日期" prop="acceptanceDate">
            {{ form.acceptanceDate }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label-width="100px" label="建设单位" prop="developerName">
            {{ form.developerName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="100px" label="联系人" prop="developerContactsName">
            {{ form.developerContactsName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="100px" label="电话" prop="developerPhone">
            {{ form.developerPhone }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label-width="100px" label="施工单位" prop="constructionUnitName">
            {{ form.constructionUnitName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="100px" label="联系人" prop="constructionUnitContactsName">
            {{ form.constructionUnitContactsName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="100px" label="电话" prop="constructionUnitPhone">
            {{ form.constructionUnitPhone }}
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle">竣工结算审计送审资料清单</div>
      <el-row>
        <el-col>
          <el-table
            ref="table"
            :data="tableData"
            :model="tableData"
            v-loading="loading"
            max-height="450"
            highlight-current-row
          >
            <el-table-column label="序号" width="100">
              <template #default="{ $index }">
                <span>{{ $index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column label="纸质" width="100">
              <template #default="{ row }">
                <el-tag :type="row.paperBased | tureOrFalseTag2">{{ row.paperBased | tureOrFalse }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="资料名称">
              <template #default="{ row }">
                <pre class="pre-style">{{ row.name }}</pre>
              </template>
            </el-table-column>
            <el-table-column label="上传资料" width="280">
              <template #default="{ row }">
                <el-upload
                  class="upload-demo"
                  action="/admin/sys-file/upload"
                  :on-preview="handlePreview"
                  :show-file-list="true"
                  :file-list="row.fileList">
                </el-upload>
              </template>
            </el-table-column>
            <el-table-column label="备注" width="280">
              <template #default="{ row }">
                <pre class="pre-style">{{ row.remark }}</pre>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import {getNotice} from "@/api/adis/project/notice";

export default {
  name: 'SettlementAuditView',
  props: {
    id: {
      type: String,
      default: ''
    },
    params: {
      type: Object,
    },
    isAudit: {
      type: Boolean,
      default: false,
    }
  },
  components: {},
  dictTypes: ['audit_type', 'project_progress', 'audit_way', 'organization_type'],
  data() {
    return {
      tableData : [],
      form: {},
      loading: false,
    }
  },
  watch:{
    id: {
      handler(val) {
        if (val) {
          getNotice(this.id).then((noticeResponse) => {
            if (noticeResponse.data.data !== null){
              this.handleNoticeResponse(noticeResponse.data.data)
              this.$emit('data-loaded', true);
            } else {
              this.$emit('data-loaded', false);
            }
          }).catch(() => {
            this.$emit('data-loaded', false);
          })
        }
      },deep: true, immediate: true
    },
    params: {
      handler(val) {
        if (val) {
          this.handleNoticeResponse(val)
        }
      },deep: true, immediate: true
    },
  },
  methods: {
    handleNoticeResponse(val) {
      this.$set(this, "form", val);
      this.form.projectYear = this.form.projectYear + '';
      this.tableData = this.form.noticeAttachments || []
      this.tableData.forEach(item => {
        item.fileList = []
        item.attachments.forEach(col => {
          item.fileList.push({name: col.fileName, url: col.fileUrl})
        })
      })
    },
    openWord() {
      if(!this.form.wordFile) {
        this.$message({
          type: "warning",
          message: "该项尚未上传相关文书!"
        });
        return;
      }
      // this.$router.push({path:'/webOffice', query: {url: this.form.wordFile}})
      const { href } = this.$router.resolve({
        path: '/webOffice',
        query: {
          url: this.form.wordFile,
          type: this.isAudit ? 'edit' : 'view',
        }
      });
      window.open(href, '_blank');
    },
    handlePreview(file) {
      window.open(file.url ? file.url : file.response.data.url)
    },
  }
}
</script>

